﻿using Levfier.Proccessors.Parameters;
using System;
namespace Levfier.Proccessors.Gain
{
    /// <summary>
    /// 上下対称線形ゲイン
    /// </summary>
    [Serializable]
    public class LinearGain : Proccessor
    {
        /// <summary>
        /// ゲインに関するパラメータ
        /// </summary>
        private ProccessParameter gainParam;

        /// <summary>
        /// 正負に関するパラメータ
        /// </summary>
        private ProccessParameter invertParam;

        /// <summary>
        /// 入力を線形増幅する
        /// </summary>
        /// <param name="input">入力</param>
        /// <param name="output">出力</param>
        protected override void InnerProccess(double[] inputBuffer, double[] outputBuffer)
        {
            //パラメータを取り出す
            double gain = ProccessParameter.ConvertDBToValue(gainParam.Value);
            if (0 < this.invertParam.Value)
            {
                gain = -gain;
            }

            //計算
            for(int i = 0 ; i < inputBuffer.Length ; i++)
            {
                outputBuffer[i] = gain * inputBuffer[i];
            }
        }

        /// <summary>
        /// パラメータを初期化する
        /// </summary>
        protected override void InitParameters()
        {
            this.gainParam = new ProccessParameter();
            this.gainParam.Name = "Gain[dB]";
            this.gainParam.Value = 0.0d;
            this.gainParam.MaxValue = 100.0d;
            this.gainParam.MinValue = -100.0d;
            this.gainParam.Step = 1.0d;
            this.parameters.Add(this.gainParam.Name, this.gainParam);
            
            this.invertParam = new ProccessParameter();
            this.invertParam.Type = ParameterType.Bool;
            this.invertParam.Name = "Invert";
            this.invertParam.Value = 0.0d;
            this.invertParam.MaxValue = 1.0d;
            this.invertParam.MinValue = 0.0d;
            this.invertParam.Step = 1.0d;
            this.parameters.Add(this.invertParam.Name, this.invertParam);
        }
    }
}
